package hw20170814.q2;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class EqualAnswer {
	private Connection conn = null;
	private PreparedStatement pst = null;
	private ResultSet rs = null;
	private Dbutil db = new Dbutil();
	private Scanner sc = new Scanner(System.in);

	public void selectType() {
		System.out.println("请输入你需要判断对错的题型");
		System.err.println("请输入提醒前面的序号");
		System.out.println("1.填空");
		System.out.println("2.单选");
		System.out.println("3.多选");
		System.out.println("4.判断");
		int i = sc.nextInt();
		switch (i) {
		case 1:
			other(i);
			break;
		case 2:
			other(i);
			break;
		case 3:
			duoXuan();
			break;
		case 4:
			other(i);
			break;
		default:
			System.out.println("请输入正确的类型序号！");
			selectType();
			break;
		}
	}

	public void duoXuan() {
		int i = 0;
		System.out.println("请输入你的答案");
		String a = sc.next();
		String sql = "SELECT duoXuan('" + a + "');";
		try {
			conn = db.getConnection();
			pst = conn.prepareStatement(sql);
			rs = pst.executeQuery();
			if (rs.next()) {
				i = rs.getInt(1);
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		System.out.println(i);
	}

	public void other(int id) {
		int i = 0;
		System.out.println("请输入你的答案");
		String a = sc.next();
		String sql = "select other('" + a + "'," + id + ")";

		try {
			conn = db.getConnection();
			pst = conn.prepareStatement(sql);
			rs = pst.executeQuery();
			if (rs.next()) {
				i = rs.getInt(1);
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		System.out.println(i);
	}

}
